﻿using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumTest
{
    [TestClass]
    public class TestHeader
    {
        private ChromeDriver driver;
        string path;
        [TestInitialize]
        public void Setup()
        {
            string projectname = "seleniumtesting111";
            string path = Directory.GetCurrentDirectory().Substring(0, Directory.GetCurrentDirectory().LastIndexOf(@"seleniumtesting111") + projectname.Length);
            ChromeOptions incognito = new ChromeOptions();
            incognito.AddArgument("--incognito");
            driver = new ChromeDriver(path, incognito);
            string baseURL = "localhost:8080";
            driver.Navigate().GoToUrl(baseURL);
        }

        [TestCleanup]
        public void CleanUp()
        {
            driver.Quit();
        }

        [TestMethod]
        [Description("Test header is visible")]
        public void TestHeaderEnabled()
        {
            var element = driver.FindElement(By.TagName("header")).Displayed;
            Assert.IsTrue(element);
        }

        [TestMethod]
        [Description("Test nav is visible")]
        public void TestNavIsVisible()
        {
            var element = driver.FindElement(By.TagName("nav")).Displayed;
            Assert.IsTrue(element);
        }

        [TestMethod]
        [Description("Test available navigations")]
        public void TestAvaibleNav()
        {
            var projekter = driver.FindElementByClassName("nav").FindElements(By.TagName("li"));
            bool projectsPresent = false;
            bool organizationPresent = false;
            bool cartPresent = false;
            foreach (var webElement in projekter)
            {
                switch (webElement.Text)
                {
                    case "PROJEKTER":
                        projectsPresent = true;
                        break;
                    case "ORGANISATIONER":
                        organizationPresent = true;
                        break;
                    case "INDKØBSKURV":
                        cartPresent = true;
                        break;
                }
            }
            Assert.IsTrue(projectsPresent);
            Assert.IsTrue(organizationPresent);
            Assert.IsTrue(cartPresent);
        }
    }
}
